
	******************************************************************
	**
	**
	**		NAME:		GUY GROSSMAN, YOTAM MARGALIT, TAMAR MITTS
	**		DATE: 		December 15, 2021
	**		PROJECT: 	Israel Hayom
	**		DETAILS: 	This code generates Table 4
	**		Version: 	Stata MP 16
	**
	******************************************************************
	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

clear
version 16
set scheme plotplain
set more off

capture cd "~/dropbox/Israeli Newspapers Study/JOP_REPLICATION/Dataverse submission"

* Bring in period dataset at locality level

use "Data/yeshuv_period_final_Figs.dta", clear
tsset uniqueid period
sort uniqueid period
	
// define covariates
gl interactions i.period#c.ltd i.period#c.lpop i.period#c.matriccert_pcnt_08 i.period#c.europe_pcnt_08 i.period#c.pop_share1829 i.period#c.pop_share3049 i.period#c.pop_share5065 i.period#c.pop_share66 i.period#c.religion_pcnt i.period#c.asia_pcnt_08
su $interactions

gl covs ltd lpop matriccert_pcnt_08 europe_pcnt_08 pop_share1829 pop_share3049 pop_share5065 pop_share66 asia_pcnt_08 religion_pcnt
su $covs

***************************************************************************
* Regressions produce results for Table 4 for Panel A (BRB) and C (Likud) *
***************************************************************************

estimates drop _all

foreach var in BRB Plikud{

* 2009 data - No covariates
	
bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D1 (IHE = IVsm) `var'Pre if period==2 [aw=potential],   cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm1
	
* 2009 data - With covariates

bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D1 (IHE = IVsm) `var'Pre $covs if period==2 [aw=potential],  cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm2
	
* 2013 data - No covariates

bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D2 (IHE = IVsm) `var'Pre if period==3 [aw=potential],  cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm3
	
* 2013 data - With covariates
	
bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D2 (IHE = IVsm) `var'Pre $covs if period==3 [aw=potential],  cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm4
	
* 2015 data - No covariates
			
bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D3 (IHE = IVsm) `var'Pre if period==4 [aw=potential],  cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm5
	
* 2015 data - With covariates

bootstrap, reps(250) seed(1712) cl(area_num) idcl(new_area_num) group(uniqueid) force : ivreg2 `var'D3 (IHE = IVsm) `var'Pre $covs if period==4 [aw=potential],  cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	estadd local boot "Yes"
	capture est sto `var'IVsm6
	
	}

	* Bring in dataset at media market level

	use "Data/arealong_final.dta", clear
		
	replace israelhayom_percent_electionyear =0 if israelhayom_percent_electionyear == . & year<2007

	replace israelhayom_percent=0 if israelhayom_percent==. & year<2007
	drop if area_num >25

	ren israelhayom_percent_electionyear IHE
	keep if IHE!=. 
	tabulate year, gen(YEAR)

	tabstat IHE, by(year)
	table area_num year, c(mean IHE)

	* gen running number for year 	
	egen yr = group(year)
	move yr year
		
	gen ltd = log(travel_dist)	
	gen lpop= log(potential)
	gen turnout = voters/potential
	su lpop turnout

	* generate turnout var
	replace turnout = 1 if turnout>1
	replace turnout = turnout*100
	tab year, summ(turnout)

	* generate otherpapers var for attentativeness measure
	egen otherpapers=rowtotal(maariv_percent haaretz_percent globes_percent marker_percent calcalist_percent israelpost_percent makorrishon_percent) if year==2006
		bysort area_num: egen otherpapers2006=max(otherpapers)
		drop otherpapers

	gl interactions i.yr#c.lpop i.yr#c.europe_pcnt_08 i.yr#c.matriccert_pcnt_08 i.yr#c.age_median_08 
	su $interactions

	gl covs lpop europe_pcnt_08 matriccert_pcnt_08 age_median_08 
	su $covs	

	ren BIG_rightbloc BRB

	ren secular_max IVsm
	ren secular_max07H1 IVsm07H1
	ren sec_max06h2_07H1 IVsm06h2_07H1

	tabstat IVsm IVsm07H1 IVsm06h2_07H1,  by(year)
	corr IVsm IVsm07H1 IVsm06h2_07H1
	drop IVsm

	bysort area_num: egen IVsm=mean(IVsm07H1)
	bysort area_num: egen IVsmp=mean(IVsm06h2_07H1)
	tabstat IVsm IVsmp, by(year)
	drop IVsm07H1 IVsm06h2_07H1
		
	* generate variable of base level of support for right bloc and Likud
	foreach var in BRB Plikud {
		gen `var'0 = `var' if yr==1
		bysort area_num: egen `var'Pre = mean(`var'0)
		drop `var'0
		}
		
		
	replace period ="1" if period==""
	replace period ="1" if period=="2006"
	replace period ="2" if period=="2009"
	replace period ="3" if period=="2013"
	replace period ="4" if period=="2015"
	destring period, replace

	sort area_num yr
	tsset area_num yr

	foreach var in BRB Plikud {
		gen l`var' = l.`var'
		gen `var'D1 = `var'-l.`var'
		gen l2`var' = l2.`var'
		gen `var'D2 = `var'-l2.`var'
		gen l3`var' = l3.`var'
		gen `var'D3 = `var'-l3.`var'
		drop l`var' l2`var' l3`var'
		}
		
	***************************************************************************
	* Regressions produce results for Table 4 for Panel B (BRB) and D (Likud) *
	***************************************************************************

	foreach var in BRB Plikud {
		
	* 2009 data - No covariates
	
	ivreg2 `var'D1 (IHE = IVsm) `var'Pre if period==2 [aw=potential], gmm2s  cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	capture est sto m_`var'1
	
	* 2009 data - With covariates
	
	ivreg2 `var'D1 (IHE = IVsm) `var'Pre $covs if period==2 [aw=potential], gmm2s cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	capture est sto m_`var'2
	
	* 2013 data - No covariates
	
	ivreg2 `var'D2 (IHE = IVsm) `var'Pre if period==3 [aw=potential], gmm2s cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	capture est sto m_`var'3
	
	* 2013 data - With covariates
	
	ivreg2 `var'D2 (IHE = IVsm) `var'Pre $covs if period==3 [aw=potential], gmm2s cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	capture est sto m_`var'4
	
	* 2015 data - No covariates
	
	ivreg2 `var'D3 (IHE = IVsm) `var'Pre if period==4 [aw=potential], gmm2s cl(area_num)
	estadd local covs "No"
	estadd local base "Yes"
	capture est sto m_`var'5
	
	* 2015 data - With covariates
	
	ivreg2 `var'D3 (IHE = IVsm) `var'Pre $covs if period==4 [aw=potential], gmm2s cl(area_num)
	estadd local covs "Yes"
	estadd local base "Yes"
	capture est sto m_`var'6
			
	}
	
	**********************************************
	* Appending all panels to create the Table 4 *
	**********************************************
	
	* Panel A
	
	# delimit ;
		esttab BRB* 
		using "Tables/Table_4.tex", replace
		keep(IHE _cons)
		varlabels(IHE "IH exposure" _cons "Constant")
		cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par))
		starlevels(* .10 ** .05 *** .01) 
		mgroups("\textbf{2009}" "\textbf{2013}" "\textbf{2015}", pattern(1 0 1 0 1 0 )
		span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) nomtitles
		posthead("\midrule \multicolumn{6}{l}{\textbf{\textit{Panel A: Locality level}}} \\ \midrule")
		postfoot("")
		stats(covs base N, labels("Covariates" "Base DV" "N")
		fmt(0 0 0)) collabels(none) label booktabs
		;
		
	#delimit cr	
	
	* Panel B
	
	# delimit ;
	esttab m_BRB* 
	using "Tables/Table_4.tex", append
		keep(IHE _cons)
		varlabels(IHE "IH exposure" _cons "Constant")
		cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par))
		starlevels(* .10 ** .05 *** .01)
		prehead("")
		posthead("\midrule \multicolumn{6}{l}{\textbf{\textit{Panel B: Media market level}}} \\ \midrule")
		postfoot("")
		stats(covs base N, labels("Covariates" "Base DV" "N")
		fmt(0 0 0)) collabels(, none) mlabels(, none) nonumbers label
		;

	#delimit cr	
	
	* Panel C
	
	# delimit ;
		esttab Plikud* 
		using "Tables/Table_4.tex", append
		keep(IHE _cons)
		varlabels(IHE "IH exposure" _cons "Constant")
		cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par))
		starlevels(* .10 ** .05 *** .01) 
		mgroups("\textbf{2009}" "\textbf{2013}" "\textbf{2015}", pattern(1 0 1 0 1 0 )
		span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) nomtitles
		prehead("\midrule")
		posthead("\midrule \multicolumn{6}{l}{\textbf{\textit{Panel C: Locality level}}} \\ \midrule")
		postfoot("")
		stats(covs base N, labels("Covariates" "Base DV" "N")
		fmt(0 0 0)) collabels(none) label booktabs
		;
		
	#delimit cr	
	
	* Panel D
	
	# delimit ;
	esttab m_Plikud* 
	using "Tables/Table_4.tex", append
		keep(IHE _cons)
		varlabels(IHE "IH exposure" _cons "Constant")
		cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par))
		starlevels(* .10 ** .05 *** .01)
		prehead("")
		posthead("\midrule \multicolumn{6}{l}{\textbf{\textit{Panel D: Media market level}}} \\ \midrule")
		stats(covs base N, labels("Covariates" "Base DV" "N")
		fmt(0 0 0)) collabels(, none) mlabels(, none) nonumbers label booktabs nonotes
		;
		
	#delimit cr	
	
